home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 1997 December / PC Pro December 1997 CD-Rom coverdisc.iso / symantec / dbAnywh / JAVA.BIN / CLASSES.ZIP / sun / tools / tree / ArrayAccessExpression.class (.txt) < prev    next >
Encoding:
Java Class File  |  1996-12-14  |  4.0 KB  |  142 lines

  1. package sun.tools.tree;
  2.  
  3. import java.io.PrintStream;
  4. import java.util.Hashtable;
  5. import sun.tools.asm.Assembler;
  6. import sun.tools.java.Constants;
  7. import sun.tools.java.Environment;
  8. import sun.tools.java.Type;
  9.  
  10. public class ArrayAccessExpression extends UnaryExpression {
  11.    Expression index;
  12.  
  13.    public ArrayAccessExpression(int var1, Expression var2, Expression var3) {
  14.       super(48, var1, Type.tError, var2);
  15.       this.index = var3;
  16.    }
  17.  
  18.    public long checkValue(Environment var1, Context var2, long var3, Hashtable var5) {
  19.       var3 = super.right.checkValue(var1, var2, var3, var5);
  20.       if (this.index == null) {
  21.          var1.error(super.where, "array.index.required");
  22.          return var3;
  23.       } else {
  24.          var3 = this.index.checkValue(var1, var2, var3, var5);
  25.          this.index = ((Node)this).convert(var1, var2, Type.tInt, this.index);
  26.          if (!super.right.type.isType(9)) {
  27.             if (!super.right.type.isType(13)) {
  28.                var1.error(super.where, "not.array", super.right.type);
  29.             }
  30.  
  31.             return var3;
  32.          } else {
  33.             super.type = super.right.type.getElementType();
  34.             return var3;
  35.          }
  36.       }
  37.    }
  38.  
  39.    public long checkLHS(Environment var1, Context var2, long var3, Hashtable var5) {
  40.       return this.checkValue(var1, var2, var3, var5);
  41.    }
  42.  
  43.    public long checkAssignOp(Environment var1, Context var2, long var3, Hashtable var5, Expression var6) {
  44.       return this.checkValue(var1, var2, var3, var5);
  45.    }
  46.  
  47.    Type toType(Environment var1, Context var2) {
  48.       return this.toType(var1, super.right.toType(var1, var2));
  49.    }
  50.  
  51.    Type toType(Environment var1, Type var2) {
  52.       if (this.index != null) {
  53.          var1.error(this.index.where, "array.dim.in.type");
  54.       }
  55.  
  56.       return Type.tArray(var2);
  57.    }
  58.  
  59.    public Expression inline(Environment var1, Context var2) {
  60.       return (new CommaExpression(super.where, super.right, this.index)).inline(var1, var2);
  61.    }
  62.  
  63.    public Expression inlineValue(Environment var1, Context var2) {
  64.       super.right = super.right.inlineValue(var1, var2);
  65.       this.index = this.index.inlineValue(var1, var2);
  66.       return this;
  67.    }
  68.  
  69.    public Expression inlineLHS(Environment var1, Context var2) {
  70.       return this.inlineValue(var1, var2);
  71.    }
  72.  
  73.    public Expression copyInline(Context var1) {
  74.       ArrayAccessExpression var2 = (ArrayAccessExpression)((Node)this).clone();
  75.       var2.right = super.right.copyInline(var1);
  76.       var2.index = this.index.copyInline(var1);
  77.       return var2;
  78.    }
  79.  
  80.    public int costInline(int var1) {
  81.       return 1 + super.right.costInline(var1) + this.index.costInline(var1);
  82.    }
  83.  
  84.    int codeLValue(Environment var1, Context var2, Assembler var3) {
  85.       super.right.codeValue(var1, var2, var3);
  86.       this.index.codeValue(var1, var2, var3);
  87.       return 2;
  88.    }
  89.  
  90.    void codeLoad(Environment var1, Context var2, Assembler var3) {
  91.       switch (super.type.getTypeCode()) {
  92.          case 0:
  93.          case 1:
  94.             var3.add(super.where, 51);
  95.             return;
  96.          case 2:
  97.             var3.add(super.where, 52);
  98.             return;
  99.          case 3:
  100.             var3.add(super.where, 53);
  101.             return;
  102.          default:
  103.             var3.add(super.where, 46 + super.type.getTypeCodeOffset());
  104.       }
  105.    }
  106.  
  107.    void codeStore(Environment var1, Context var2, Assembler var3) {
  108.       switch (super.type.getTypeCode()) {
  109.          case 0:
  110.          case 1:
  111.             var3.add(super.where, 84);
  112.             return;
  113.          case 2:
  114.             var3.add(super.where, 85);
  115.             return;
  116.          case 3:
  117.             var3.add(super.where, 86);
  118.             return;
  119.          default:
  120.             var3.add(super.where, 79 + super.type.getTypeCodeOffset());
  121.       }
  122.    }
  123.  
  124.    public void codeValue(Environment var1, Context var2, Assembler var3) {
  125.       this.codeLValue(var1, var2, var3);
  126.       this.codeLoad(var1, var2, var3);
  127.    }
  128.  
  129.    public void print(PrintStream var1) {
  130.       var1.print("(" + Constants.opNames[super.op] + " ");
  131.       super.right.print(var1);
  132.       var1.print(" ");
  133.       if (this.index != null) {
  134.          this.index.print(var1);
  135.       } else {
  136.          var1.print("<empty>");
  137.       }
  138.  
  139.       var1.print(")");
  140.    }
  141. }
  142.